<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/9/24
 * Time: 9:48
 */

namespace app\model;


use think\Model;

class BaseModel extends Model
{

    /**
     * @return mixed
     * @throws \Exception
     * 统一更新和添加
     */
    public function add_update(Model $model,$data){

        if(!is_array($data)){
            exception('数据格式不正确');
        }
        if(empty($data['id'])){
            //新增
            $model->allowField(true)->data($data,true)->isUpdate(false)->save();
        }else{
            //修改
            $model->allowField(true)->save($data,$data['id']);
        }
        return $model->id;
    }

}